<%@page import="com.utils.Des"%>
<%@ page language="java" import="java.util.*,com.beans.*" pageEncoding="UTF-8"%>   
<%
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>
  <head>
    <base href="<%=basePath%>">  
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/validate.css"  ></link> 
	<link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>  
	<script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
	<script>
		
		
		$(function(){
			<%
				//用做把原密码解密之后在更改
				AdminInfo admin = (AdminInfo)request.getSession().getAttribute("admin_session");
	  			request.setAttribute("admin", "a");
				String p = Des.desStr(admin.getPassword());
				request.setAttribute("password",p );
			%>
			var yuanPassword=false;  //设置全局变量   提交验证时候用  初始值设置false  防止开始就提交
			var password=false;
			var passwordchong = false;
			$("#yuanPassword").blur(function(){
				var passwrod = $(this).val();
				var pa = '${password}';
				if(passwrod==pa){
					$("#" + $(this)[0].id + "_msg").html("原密码无误").removeClass().addClass("validate_ok");
					yuanPassword = true;
				}else{
					$("#" + $(this)[0].id + "_msg").html("原密码有误").removeClass().addClass("validate_error");
					yuanPassword = false;
				}
			});
			
			$("#gengPassword").blur(function(){
				var passWord=$(this).val();
				var reg=/^[0-9A-Za-z]{6,20}$/g;
				if(reg.test(passWord)){
					$("#"+$(this)[0].id+"_msg").html("√").removeClass().addClass("validate_ok");
					password=true;
				}else{
					$("#"+$(this)[0].id+"_msg").html("密码格式错误").removeClass().addClass("validate_error");
					password=false;
				}
			});
			
			$("#gengTwoPassword").blur(function(){
				var a = $("#gengPassword").val();
				var b = $(this).val();
				if(a==b){
					$("#"+$(this)[0].id+"_msg").html("√").removeClass().addClass("validate_ok");
					passwordchong =  true;
				}else{
					$("#"+$(this)[0].id+"_msg").html("与密码不完全相同").removeClass().addClass("validate_error");
					passwordchong =  false;
				}
				if(a==""){
				$("#"+$(this)[0].id+"_msg").html("请填写密码").removeClass().addClass("validate_error");
				passwordchong = false;
			}
			});
			
			$("button").click(function(){
				var result=true;
				if(yuanPassword==false){
					$("#yuanPassword").blur();
				}
				if(password==false){
					$("#gengPassword").blur();
					result = false;
				}
				if(passwordchong==false){
					$("#gengTwoPassword").blur();
					result = false;
				}
				var session = '${admin_session}';
				if(session!=""){
					if(result==true){
							if(confirm("确认更改吗")){
								$.ajax({
									url:"AdminServlet.do",
									type:"post",
									data:{password:$("#gengPassword").val(),flag:"gengPassword",id:'${admin_session.id}'},
									success:function(data){
										$("#result_msg").html(data).removeClass().addClass("validate_ok");
										alert("更改密码后请重新登陆");
										top.location.href="${pageContext.request.contextPath }/login.jsp";//只写login.jsp ie不兼容
									}
								});
						}
					}else{
						$("#result_msg").html("请正确填写信息后提交").removeClass().addClass("validate_error");
					}
				}else{
					top.location.href="${pageContext.request.contextPath }/login.jsp";
				}
			});
		});
	</script>
  </head>
  
  <body>
  		
		
	
  <div class ="div_title">
		 <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>请修改用户密码</span></div>
	 </div>
  <table class="edit_table">
  	<tr>
  		<td>请输入原来的密码:</td>
  		<td><input type="text" name="yuanPassword" id="yuanPassword"></td>
  		<td><label id="yuanPassword_msg"></label></td>
  	</tr>
  	<tr>
  		<td>请输入要更改密码:</td>
  		<td><input type="text" name="gengPassword" id="gengPassword"></td>
  		<td><label id="gengPassword_msg">密码为数字或英文,6-20位</label></td>
  	</tr>
  	<tr>
  		<td>请再次输入要更改的密码:</td>
  		<td><input type="text" name="gengTwoPassword" id="gengTwoPassword"></td>
  		<td><label id="gengTwoPassword_msg"></label></td>
  	</tr>
  	<tr>
  		<td><button>更改</button></td>
  		<td><label id="result_msg"></label></td>
  	</tr>
  </table>
  
  	
  	
  
  </body>
</html>